package com.dreamoriole.dao;

import java.io.*;
import java.util.Properties;

import org.apache.log4j.Logger;

public class FinanceObjectDaoFactory {
	private Object objDao = null;
	private static FinanceObjectDaoFactory instance = new FinanceObjectDaoFactory();
	private static Properties prop = null;
	private static Logger log = Logger.getLogger(FinanceObjectDaoFactory.class);
	
	static {
		prop = new Properties();
		InputStream is = FinanceObjectDaoFactory.class.getResourceAsStream("/com/dreamoriole/cfg/db.properties");
		try {
			prop.load(is);
		} catch (IOException e) {
			log.error(e.getMessage());
			throw new ExceptionInInitializerError(e);
		}
	}
	
	public static FinanceObjectDaoFactory getInstance() {
		return instance;
	}
	public Object getObjDao(String key) {
		try {
			String className = prop.getProperty(key);
			objDao = Class.forName(className).newInstance();
		} catch (InstantiationException e) {
			log.error(e.getMessage());
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			log.error(e.getMessage());
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}
		return objDao;
	}
	
}
